home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 004 / tridi.bas (.txt) < prev    next >
Encoding:
GW-BASIC  |  1985-08-07  |  2.4 KB  |  64 lines

  1. 10  '**************************************************************************
  2. 15  '***                                                                    ***
  3. 20  '***         LINEAR EQUATION SOLUTION by TRIDIAGONAL MATRIX             ***
  4. 30  '***                                                                    ***
  5. 40  '**************************************************************************
  6. 50  '
  7. 60  '        A maximum of 500 equations can be handled by this routine
  8. 70  '
  9. 80  '***                     DIMENSION MATRIX                               ***
  10. 90   DIM A(500),B(500),C(500),D(500)
  11. 100  CLS:KEY OFF:LOCATE 10,10
  12. 110  '
  13. 120  '***                     INPUT NO. of EQUATIONS                        ***
  14. 130  '
  15. 140  INPUT "Number of Equations, N";N                  ' number of coefficients
  16. 145  LPRINT "Number of Equations, N ";N
  17. 150  LPRINT "Tridiagonal Matrix Solution for ";N;"equations
  18. 160  PRINT:PRINT
  19. 180  '
  20. 190  '***                     READ COEFFICIENTS                             ***
  21. 200  '
  22. 210  FOR I=1 TO N                                                     ' I = row
  23. 220   PRINT "Input B(";I;")=";:INPUT B(I)                    'B= Below Diagonal
  24. 225  LPRINT "B(";I;")=";B(I)
  25. 230   PRINT "Input D(";I;")=";:INPUT D(I)                  'D= Diagonal Element
  26. 235  LPRINT "D(";I;")=";D(I)
  27. 240   PRINT "Input A(";I;")=";:INPUT A(I)                    'A= Above Diagonal
  28. 245  LPRINT "A(";I;")=";A(I)
  29. 250   PRINT "Input C(";I;")=";:INPUT C(I)                   'C= Constant Vector
  30. 255  LPRINT "C(";I;")=";C(I)
  31. 260  NEXT I
  32. 270  '
  33. 280  ' ***                      PRINT HEADING                               ***
  34. 290  '
  35. 300  '
  36. 310  PRINT "Solution to Tridiagonal System of ";N;" equations by elimination."
  37. 320  LPRINT "Solution to Tridiagonal System of ";N;" equations by elimination."
  38. 325  PRINT:LPRINT
  39. 330  '
  40. 340  '***             PRINT THE NEW MATRIX VALUES                           ***
  41. 345  '        Values of Variables will be stored in C Array
  42. 350  '
  43. 360  FOR I= 2 TO N
  44. 370   R=B(I)/D(I-1)
  45. 380   D(I)=D(I)-R*A(I-1)
  46. 390   C(I)=C(I)-R*C(I-1)
  47. 400  NEXT
  48. 405  '
  49. 410  '***             BACK SUBSTITUTION                                    ***
  50. 415  '
  51. 420   C(N)=C(N)/D(N)
  52. 430   FOR I=2 TO N
  53. 440    J=N-I+1
  54. 450    C(J)=(C(J)-A(J)*C(J+1))/D(J)
  55. 460   NEXT
  56. 465  '
  57. 470  '***       PRINT OUT VALUES OF VARIABLES                              ***
  58. 475  '
  59. 480  FOR I=1 TO N
  60. 490   PRINT I,C(I)
  61. 500   LPRINT I,C(I)
  62. 510  NEXT
  63. 780  END
  64.